<div class="content" v-loading="btnloading">
    <el-form :model="secretkeyruleForm" :rules="secretkeyrules" ref="fsecretkeyruleForm" label-width="120px" label-suffix="：">
        <el-form-item label="APPID" prop="appid">
            <el-input class="maxWidth" v-model.trim="secretkeyruleForm.appid"></el-input>
            <el-text type="info" class="tipTxt" size="small">APPID</el-text>
        </el-form-item>

        <el-form-item label="APISecret" prop="sk">
            <el-input class="maxWidth" v-model.trim="secretkeyruleForm.sk"></el-input>
            <el-text type="info" class="tipTxt" size="small">APISecret</el-text>
        </el-form-item>
        <el-form-item label="APIKey" prop="ak">
            <el-input class="maxWidth" v-model.trim="secretkeyruleForm.ak"></el-input>
            <el-text type="info" class="tipTxt" size="small">APIKey</el-text>
        </el-form-item>
        <el-form-item label="状态">
            <el-switch
                v-model="secretkeyruleForm.status"
                active-text="开启"
                inactive-text="关闭"
                :active-value="1"
                :inactive-value="0"
            ></el-switch>
            <el-text type="info" class="tipTxt" size="small">开启后，系统中能够使用AI标签，AI描述功能，密钥信息填写后可以开启</el-text>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="secretkeySubmit">保存更改</el-button>
        </el-form-item>
    </el-form>
</div>
<script>
    let secretkeyMixin = {
        data() {
			return {
				secretkeyruleForm: {
					appid:"$setting['appid']",
					ak:"$setting['ak']",
					sk:"$setting['sk']",
					status:$setting['status']
				},
				secretkeyrules: {
					appid: [
						{ required: true, message: '必填项不能为空', trigger: 'blur' }
					],
					ak: [
						{ required: true, message: '必填项不能为空', trigger: 'blur' }
					],
					sk: [
						{ required: true, message: '必填项不能为空', trigger: 'blur' }
					]
				},
			}
		},
        methods: {
			secretkeySubmit(){
				var self = this;
				self.$refs.fsecretkeyruleForm.validate(async function(valid){
					if (valid) {
						var params = {
							'settingsumbit':true,
							'formhash':'{FORMHASH}',
							'appid':self.secretkeyruleForm.appid,
							'ak':self.secretkeyruleForm.ak,
							'sk':self.secretkeyruleForm.sk,
							'status':self.secretkeyruleForm.status,
						};
						
						self.btnloading = true;
						const {data: res} = await axios.post('{MOD_URL}&op=setting',params);
						if(res.success){
							 self.$message({
							 	message: '保存成功',
							 	type: 'success'
							 });
							window.location.reload();
						}else{
							self.btnloading = false;
							self.$message.error(res.msg || '提交失败');
						}
				    
					} else {
						self.$message.error('验证失败');
						self.btnloading = false;
						return false;
					}
				});
			}
		},
    }
</script>